from flask import *
from qiniu import Auth, put_file

# 上传图片
class QiniuTool():
    def __init__(self):
        ak = current_app.config.get('QINIU_AK')
        sk = current_app.config.get('QINIU_SK')
        self.name = current_app.config.get('QINIU_NAME')
        self.q = Auth(ak, sk)

    def upload(self, staticpath, staticname):
        # 生成七牛云token
        token = self.q.upload_token(self.name, staticname)

        ser = put_file(token, staticname, staticpath, version='v2')

        if ser[0]['key'] == staticname:
            print(111)
            return True
        return False

if __name__ == '__main__':
    from app import app
    with app.app_context():
        QiniuTool().upload('./../static/23423535.jpg', '23423535.jpg')